//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __RENDERUTILITY_H__
#define __RENDERUTILITY_H__

#include <RenderLibDef.h>

//////////////////////////////////////////////////////////////////////////////
//                          Pixel Render Utility                            //
//////////////////////////////////////////////////////////////////////////////
INLINE Void PixelRenderRGB24ToRGB24(
                Address dst, Address src)
{
    *((Pixel*)dst) = *((Pixel*)src);
}

INLINE Void PixelRenderRGB24ToRGB24WithOpacity(
                Address destination, Address source, UInt8 srcOpacity)
{
    // if 0xFF == srcOpacity || 0x00 == srcOpacity
    // you must be call PixelRenderRGB24ToRGB24(Pixel&, Pixel&)
    // or return directly.
    //
    assert(0xFF != srcOpacity && 0x00 != srcOpacity);

    Pixel *dst = (Pixel *)destination;
    Pixel *src = (Pixel *)source;

    dst->r = ((src->r * srcOpacity)>>8) + ((dst->r * (0xFF - srcOpacity))>>8);
    dst->g = ((src->g * srcOpacity)>>8) + ((dst->g * (0xFF - srcOpacity))>>8);
    dst->b = ((src->b * srcOpacity)>>8) + ((dst->b * (0xFF - srcOpacity))>>8);
}

INLINE Void PixelRenderARGB32ToRGB24(
                Address destination, Address source)
{
    Pixel *dst = (Pixel *)destination;
    Pixel *src = (Pixel *)source;

    if (0xFF == src->a) {
        *dst = *src;
    }
    else if (0x00 != src->a) {
        UInt8 srcAlpha = src->a;

        dst->r = src->r + ((dst->r * (0xFF - srcAlpha))>>8);
        dst->g = src->g + ((dst->g * (0xFF - srcAlpha))>>8);
        dst->b = src->b + ((dst->b * (0xFF - srcAlpha))>>8);
    }
}

INLINE Void PixelRenderARGB32ToRGB24WithOpacity(
                Address destination, Address source, UInt8 srcOpacity)
{
    assert(0xFF != srcOpacity && 0x00 != srcOpacity);

    Pixel *dst = (Pixel *)destination;
    Pixel *src = (Pixel *)source;

    if (0xFF == src->a) {

        dst->r = ((src->r * srcOpacity)>>8) + ((dst->r * (0xFF - srcOpacity))>>8);
        dst->g = ((src->g * srcOpacity)>>8) + ((dst->g * (0xFF - srcOpacity))>>8);
        dst->b = ((src->b * srcOpacity)>>8) + ((dst->b * (0xFF - srcOpacity))>>8);
    }
    else if (0x00 != src->a) {
        UInt32 alpha = (src->a * srcOpacity)>>8;

        dst->r = ((src->r * srcOpacity)>>8) + ((dst->r * (0xFF - alpha))>>8);
        dst->g = ((src->g * srcOpacity)>>8) + ((dst->g * (0xFF - alpha))>>8);
        dst->b = ((src->b * srcOpacity)>>8) + ((dst->b * (0xFF - alpha))>>8);
    }
}

INLINE Void PixelRenderRGB24ToARGB32(
                Address destination, Address source)
{
    Pixel *dst = (Pixel *)destination;
    Pixel *src = (Pixel *)source;

    dst->a = 0xFF;
    dst->r = src->r;
    dst->g = src->g;
    dst->b = src->b;
}

INLINE Void PixelRenderRGB24ToARGB32WithOpacity(
                Address destination, Address source, UInt8 srcOpacity)
{
    assert(0xFF != srcOpacity && 0x00 != srcOpacity);

    Pixel *dst = (Pixel *)destination;
    Pixel *src = (Pixel *)source;

    dst->a = srcOpacity + ((dst->a * (0xFF - srcOpacity))>>8);
    dst->r = ((src->r * srcOpacity)>>8) + ((dst->r * (0xFF - srcOpacity))>>8);
    dst->g = ((src->g * srcOpacity)>>8) + ((dst->g * (0xFF - srcOpacity))>>8);
    dst->b = ((src->b * srcOpacity)>>8) + ((dst->b * (0xFF - srcOpacity))>>8);
}

INLINE Void PixelRenderARGB32ToARGB32(
                Address destination, Address source)
{
    Pixel *dst = (Pixel *)destination;
    Pixel *src = (Pixel *)source;

    if (0xFF == src->a) {
        *dst = *src;
    }
    else if (0x00 != src->a) {
        UInt8 srcAlpha = src->a;

        dst->a = src->a + ((dst->a * (0xFF - srcAlpha))>>8);
        dst->r = src->r + ((dst->r * (0xFF - srcAlpha))>>8);
        dst->g = src->g + ((dst->g * (0xFF - srcAlpha))>>8);
        dst->b = src->b + ((dst->b * (0xFF - srcAlpha))>>8);
    }
}

INLINE Void PixelRenderARGB32ToARGB32WithOpacity(
                Address destination, Address source, UInt8 srcOpacity)
{
    assert(0xFF != srcOpacity && 0x00 != srcOpacity);

    Pixel *dst = (Pixel *)destination;
    Pixel *src = (Pixel *)source;

    if (0xFF == src->a) {

        dst->a = srcOpacity + ((dst->a * (0xFF - srcOpacity))>>8);
        dst->r = ((src->r * srcOpacity)>>8)
                        + ((dst->r * (0xFF - srcOpacity))>>8);
        dst->g = ((src->g * srcOpacity)>>8)
                        + ((dst->g * (0xFF - srcOpacity))>>8);
        dst->b = ((src->b * srcOpacity)>>8)
                        + ((dst->b * (0xFF - srcOpacity))>>8);
    }
    else if (0x00 != src->a) {
        UInt32 alpha = (src->a * srcOpacity)>>8;

        dst->a = alpha + ((dst->a * (0xFF - alpha))>>8);
        dst->r = ((src->r * srcOpacity)>>8) + ((dst->r * (0xFF - alpha))>>8);
        dst->g = ((src->g * srcOpacity)>>8) + ((dst->g * (0xFF - alpha))>>8);
        dst->b = ((src->b * srcOpacity)>>8) + ((dst->b * (0xFF - alpha))>>8);
    }
}

INLINE Void PixelRenderA8ToRGB24(
                Address destination, Address source, Pixel srcColor)
{
    assert(0xFF == srcColor.a);

    Pixel *dst = (Pixel *)destination;
    UInt8 *src = (UInt8 *)source;

    if (0xFF == *src) {
        *dst = srcColor;
    }
    else if (0x00 != *src) {
        dst->r = ((srcColor.r * (*src))>>8) + ((dst->r * (0xFF - (*src)))>>8);
        dst->g = ((srcColor.g * (*src))>>8) + ((dst->g * (0xFF - (*src)))>>8);
        dst->b = ((srcColor.b * (*src))>>8) + ((dst->b * (0xFF - (*src)))>>8);
    }
}

INLINE Void PixelRenderA8ToRGB24WithColorAlpha(
                Address destination, Address source, Pixel srcColor)
{
    assert(0xFF != srcColor.a && 0x00 != srcColor.a);

    Pixel *dst = (Pixel *)destination;
    UInt8 *src = (UInt8 *)source;

    if (0xFF == *src) {
        UInt8 srcAlpha = srcColor.a;

        dst->r = srcColor.r + ((dst->r * (0xFF - srcAlpha))>>8);
        dst->g = srcColor.g + ((dst->g * (0xFF - srcAlpha))>>8);
        dst->b = srcColor.b + ((dst->b * (0xFF - srcAlpha))>>8);
    }
    else if (0x00 != *src) {
        UInt32 alpha = ((*src) * srcColor.a)>>8;

        dst->r = ((srcColor.r * (*src))>>8)
                        + ((dst->r * (0xFF - alpha))>>8);
        dst->g = ((srcColor.g * (*src))>>8)
                        + ((dst->g * (0xFF - alpha))>>8);
        dst->b = ((srcColor.b * (*src))>>8)
                        + ((dst->b * (0xFF - alpha))>>8);
    }
}

INLINE Void PixelRenderA8ToARGB32(
                Address destination, Address source, Pixel srcColor)
{
    assert(0xFF == srcColor.a);

    Pixel* dst = (Pixel *)destination;
    UInt8 *src = (UInt8 *)source;

    if (0xFF == *src) {
        *dst = srcColor;
    }
    else if (0x00 != *src) {
        dst->a = (*src) + ((dst->a * (0xFF - (*src)))>>8);
        dst->r = ((srcColor.r * (*src))>>8) + ((dst->r * (0xFF - (*src)))>>8);
        dst->g = ((srcColor.g * (*src))>>8) + ((dst->g * (0xFF - (*src)))>>8);
        dst->b = ((srcColor.b * (*src))>>8) + ((dst->b * (0xFF - (*src)))>>8);
    }
}

INLINE Void PixelRenderA8ToARGB32WithColorAlpha(
                Address destination, Address source, Pixel srcColor)
{
    assert(0xFF != srcColor.a && 0x00 != srcColor.a);

    Pixel* dst = (Pixel *)destination;
    UInt8 *src = (UInt8 *)source;

    if (0xFF == *src) {
        UInt8 srcAlpha = srcColor.a;

        dst->a = srcAlpha + ((dst->a * (0xFF - srcAlpha))>>8);
        dst->r = srcColor.r + ((dst->r * (0xFF - srcAlpha))>>8);
        dst->g = srcColor.g + ((dst->g * (0xFF - srcAlpha))>>8);
        dst->b = srcColor.b + ((dst->b * (0xFF - srcAlpha))>>8);
    }
    else if (0x00 != *src) {
        UInt32 alpha = ((*src) * srcColor.a)>>8;

        dst->a = alpha + ((dst->a * (0xFF - alpha))>>8);
        dst->r = ((srcColor.r * (*src))>>8)
                        + ((dst->r * (0xFF - alpha))>>8);
        dst->g = ((srcColor.g * (*src))>>8)
                        + ((dst->g * (0xFF - alpha))>>8);
        dst->b = ((srcColor.b * (*src))>>8)
                        + ((dst->b * (0xFF - alpha))>>8);
    }
}

inline Void PixelSetColorARGB32(
                Address destination, Pixel srcColor)
{
    *((Pixel *)destination) = srcColor;
}

INLINE Void PixelSetColorARGB32WithColorAlpha(
                Address destination, Pixel srcColor)
{
    assert(0xFF != srcColor.a && 0x00 != srcColor.a);

    Pixel* dst = (Pixel *)destination;
    Int32 alpha = srcColor.a;

    dst->a = srcColor.a + ((dst->a * (0xFF - alpha))>>8);
    dst->r = srcColor.r + ((dst->r * (0xFF - alpha))>>8);
    dst->g = srcColor.g + ((dst->g * (0xFF - alpha))>>8);
    dst->b = srcColor.b + ((dst->b * (0xFF - alpha))>>8);
}


INLINE Pixel BilinearQuadRGB24(
                Address Color0, Address Color1, UInt32 u_8,UInt32 v_8)
{
    Pixel result;

    Pixel* color0 = (Pixel *)Color0;
    Pixel* color1 = (Pixel *)Color1;

    UInt32 pm3_16 = u_8 * v_8;
    UInt32 pm2_16 = (u_8<<8) - pm3_16;
    UInt32 pm1_16 = (v_8<<8) - pm3_16;
    UInt32 pm0_16 = (0x0000FFFF) - pm1_16 - pm2_16 - pm3_16;

    result.r = (UInt8)((pm0_16 * color0[0].r + pm2_16 * color0[1].r + pm1_16 * color1[0].r + pm3_16 * color1[1].r)>>16);
    result.g = (UInt8)((pm0_16 * color0[0].g + pm2_16 * color0[1].g + pm1_16 * color1[0].g + pm3_16 * color1[1].g)>>16);
    result.b = (UInt8)((pm0_16 * color0[0].b + pm2_16 * color0[1].b + pm1_16 * color1[0].b + pm3_16 * color1[1].b)>>16);

    return result;
}

INLINE Pixel BilinearQuadARGB32(
                Address Color0, Address Color1, UInt32 u_8,UInt32 v_8)
{
    Pixel result;

    Pixel* color0 = (Pixel *)Color0;
    Pixel* color1 = (Pixel *)Color1;

    UInt32 pm3_8 = (u_8 * v_8)>>8;
    UInt32 pm2_8 = u_8 - pm3_8;
    UInt32 pm1_8 = v_8 - pm3_8;
    UInt32 pm0_8 = 256 - pm1_8 - pm2_8 - pm3_8;

    UInt32 color = *(UInt32*)(color0);
    UInt32 BR = (color & 0x00FF00FF) * pm0_8;
    UInt32 GA = ((color & 0xFF00FF00)>>8) * pm0_8;
                 color =( (UInt32*)(color0))[1];
                 GA += ((color & 0xFF00FF00)>>8) * pm2_8;
                 BR += (color & 0x00FF00FF) * pm2_8;
                 color = *(UInt32*)(color1);
                 GA += ((color & 0xFF00FF00)>>8) * pm1_8;
                 BR += (color & 0x00FF00FF) * pm1_8;
                 color = ((UInt32*)(color1))[1];
                 GA += ((color & 0xFF00FF00)>>8) * pm3_8;
                 BR += (color & 0x00FF00FF) * pm3_8;

    *(UInt32*)(&result) = (GA & 0xFF00FF00) | ((BR & 0xFF00FF00)>>8);

    return result;
}

INLINE UInt8 BilinearQuadA8(
                Address Color0, Address Color1, UInt32 u_8, UInt32 v_8)
{
    UInt8* color0 = (UInt8 *)Color0;
    UInt8* color1 = (UInt8 *)Color1;

    UInt32 pm3_8 = (u_8 * v_8)>>8;
    UInt32 pm2_8 = u_8 - pm3_8;
    UInt32 pm1_8 = v_8 - pm3_8;
    UInt32 pm0_8 = 256 - pm1_8 - pm2_8 - pm3_8;

    return (UInt8)((pm0_8 * color0[0] + pm2_8 * color0[1]
            + pm1_8 * color1[0] + pm3_8 * color1[1])>>8);
}

INLINE UInt16 Pixel888To565(Address source)
{
    Pixel* src = (Pixel *)source;

    UInt16 temp = src->b>>3;
    temp |= (src->g>>2)<<5;
    temp |= (src->r>>3)<<11;

    return temp;
}

INLINE UInt32 Pixel888To666(Address source)
{
    Pixel* src = (Pixel *)source;

    UInt32 temp = src->b>>2;
    temp |= (src->g>>2)<<6;
    temp |= (src->r>>2)<<12;

    return temp;
}

#ifdef __cplusplus
extern "C" {
#endif

////////////////////////////////////////////////////////////////////////////
//                          ScanLine Render Utility                       //
////////////////////////////////////////////////////////////////////////////

Void ScanLineRGB24ToRGB24(
                Address destination, Address source, Int32 stride);

Void ScanLineRGB24ToRGB24WithOpacity(
                Address destination, Address source, Int32 stride,
                UInt8 srcOpacity);

Void ScanLineARGB32ToRGB24(
                Address destination, Address source, Int32 stride);

Void ScanLineARGB32ToRGB24WithOpacity(
                Address destination, Address source, Int32 stride,
                UInt8 srcOpacity);

Void ScanLineRGB24ToARGB32(
                Address destination, Address source, Int32 stride);

Void ScanLineRGB24ToARGB32WithOpacity(
                Address destination, Address source, Int32 stride,
                UInt8 srcOpacity);

Void ScanLineARGB32ToARGB32(
                Address destination, Address source, Int32 stride);

Void ScanLineARGB32ToARGB32WithOpacity(
                Address destination, Address source, Int32 stride,
                UInt8 srcOpacity);

Void ScanLineA8ToRGB24(
                Address destination, Address src, Int32 stride,
                Pixel srcColor);

Void ScanLineA8ToRGB24WithColorAlpha(
                Address destination, Address src, Int32 stride,
                Pixel srcColor);

Void ScanLineA8ToARGB32(
                Address destination, Address src, Int32 stride,
                Pixel srcColor);

Void ScanLineA8ToARGB32WithColorAlpha(
                Address destination, Address src, Int32 stride,
                Pixel srcColor);

Void ScanLineRGB24ToRGB24_V4(
                Address destination, Address source, Int32 stride);

Void ScanLineRGB24ToRGB24WithOpacity_V4(
                Address destination, Address source, Int32 stride,
                UInt8 srcOpacity);

Void ScanLineSetColorARGB32_V4(
                Address destination, Int32 stride, Pixel srcColor);

Void ScanLineRGB24ToARGB32WithOpacity_V4(
                Address destination, Address source, Int32 stride,
                UInt8 srcOpacity);

Void ScanLineRGB24ToARGB32_V4(
                Address destination, Address source, Int32 stride);

Void ScanLineSetColorARGB32WithColorAlpha_V4(
                Address destination, Int32 stride, Pixel srcColor);


////////////////////////////////////////////////////////////////////////////
//                          ScanLine Set Color Utility                    //
////////////////////////////////////////////////////////////////////////////

Void ScanLineSetColorARGB32(
                Address destination, Int32 stride, Pixel srcColor);
Void ScanLineSetColorARGB32WithColorAlpha(
                Address destination, Int32 stride, Pixel srcColor);


////////////////////////////////////////////////////////////////////////////
//                          ScanLine Zoom Utility                         //
////////////////////////////////////////////////////////////////////////////

Void ZoomScanLineRGB24ToRGB24(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                UInt32 srcX);

Void ZoomScanLineRGB24ToRGB24WithOpacity(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                UInt8 opacity,
                UInt32 srcX);

Void ZoomScanLineRGB24ToARGB32(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                UInt32 srcX);

Void ZoomScanLineRGB24ToARGB32WithOpacity(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                UInt8 opacity,
                UInt32 srcX);

Void ZoomScanLineARGB32ToRGB24(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                UInt32 srcX);

Void ZoomScanLineARGB32ToRGB24WithOpacity(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                UInt8 opacity,
                UInt32 srcX);

Void ZoomScanLineARGB32ToARGB32(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                UInt32 srcX);

Void ZoomScanLineARGB32ToARGB32WithOpacity(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                UInt8 opacity,
                UInt32 srcX);

Void ZoomScanLineA8ToRGB24(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                Pixel srcColor);

Void ZoomScanLineA8ToRGB24WithColorAlpha(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                Pixel srcColor);

Void ZoomScanLineA8ToARGB32(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                Pixel srcColor);

Void ZoomScanLineA8ToARGB32WithColorAlpha(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                Pixel srcColor);

UInt32 ZoomScanLineRGB24ToRGB24_V4(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16);

UInt32 ZoomScanLineRGB24ToRGB24WithOpacity_V4(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                UInt8 opacity);

UInt32 ZoomScanLineARGB32ToARGB32_V4(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16);

UInt32 ZoomScanLineARGB32ToARGB32WithOpacity_V4(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                UInt8 opacity);

UInt32 ZoomScanLineRGB24ToARGB32_V4(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16);

UInt32 ZoomScanLineRGB24ToARGB32WithOpacity_V4(
                Address destination, Int32 stride,
                Address source, UInt32 xrIntFloat_16,
                UInt8 opacity);


////////////////////////////////////////////////////////////////////////////
//                          ScanLine Bilinear Utility                     //
////////////////////////////////////////////////////////////////////////////

Void BilinearScanLineRGB24ToRGB24(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride,
                UInt32 srcX);

Void BilinearScanLineRGB24ToRGB24WithOpacity(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride,
                UInt8 opacity, UInt32 srcX);

Void BilinearScanLineRGB24ToARGB32(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride,
                UInt32 srcX);

Void BilinearScanLineRGB24ToARGB32WithOpacity(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride,
                UInt8 opacity, UInt32 srcX);

Void BilinearScanLineARGB32ToRGB24(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride,
                UInt32 srcX);

Void BilinearScanLineARGB32ToRGB24WithOpacity(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride,
                UInt8 opacity, UInt32 srcX);

Void BilinearScanLineARGB32ToARGB32(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride,
                UInt32 srcX);

Void BilinearScanLineARGB32ToARGB32WithOpacity(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride,
                UInt8 opacity, UInt32 srcX);

Void BilinearScanLineA8ToRGB24(
                Address destination, Int32 stride,
                Address source, Int32 srcPitch,
                UInt32 xrIntFloat_16, UInt32 v_8,
                Pixel srcColor);

Void BilinearScanLineA8ToRGB24WithColorAlpha(
                Address destination, Int32 stride,
                Address source, Int32 srcPitch,
                UInt32 xrIntFloat_16, UInt32 v_8,
                Pixel srcColor);

Void BilinearScanLineA8ToARGB32(
                Address destination, Int32 stride,
                Address source, Int32 srcPitch,
                UInt32 xrIntFloat_16, UInt32 v_8,
                Pixel srcColor);

Void BilinearScanLineA8ToARGB32WithColorAlpha(
                Address destination, Int32 stride,
                Address source, Int32 srcPitch,
                UInt32 xrIntFloat_16, UInt32 v_8,
                Pixel srcColor);

UInt32 BilinearScanLineRGB24ToRGB24_V4(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride);

UInt32 BilinearScanLineRGB24ToRGB24WithOpacity_V4(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride,
                UInt8 opacity);

UInt32 BilinearScanLineARGB32ToARGB32_V4(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride);

UInt32 BilinearScanLineARGB32ToARGB32WithOpacity_V4(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride,
                UInt8 opacity);

UInt32 BilinearScanLineRGB24ToARGB32_V4(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride);

UInt32 BilinearScanLineRGB24ToARGB32WithOpacity_V4(
                Address destination, Address source,
                Int32 srcPitch, UInt32 v_8,
                UInt32 xrIntFloat_16, Int32 stride,
                UInt8 opacity);

UInt32 BilinearQuadARGB32_V4(
                Address destination, Address source,
                Int32 srcPitch, UInt32 srcx_16,
                UInt32 xrIntFloat_16, UInt32 v_8);


////////////////////////////////////////////////////////////////////////////
//                          ScanLine Convert Utility                     //
////////////////////////////////////////////////////////////////////////////
Void ScanLineRECT888To565(
                Address destination, Address source, Int32 stride);

Void ScanLineRECT888To565FLIP(
                Address destination, Address source, Int32 stride);

Void ScanLineRECT888To565RCW(
                Address destination, Address source, Int32 stride,
                Int32 dstPitch);

Void ScanLineRECT888To565RCCW(
                Address destination, Address source, Int32 stride,
                Int32 dstPitch);

Void ScanLineRECT888To666(
                Address destination, Address source, Int32 stride);

Void ScanLineRECT888To666FLIP(
                Address destination, Address source, Int32 stride);

Void ScanLineRECT888To666RCW(
                Address destination, Address source, Int32 stride,
                Int32 dstPitch);

Void ScanLineRECT888To666RCCW(
                Address destination, Address source, Int32 stride,
                Int32 dstPitch);

Void ScanLineRECT888To888FLIP(
                Address destination, Address source, Int32 stride);

Void ScanLineRECT888To888RCW(
                Address destination, Address source, Int32 stride,
                Int32 dstPitch);

Void ScanLineRECT888To888RCCW(
                Address destination, Address source, Int32 stride,
                Int32 dstPitch);

#ifdef __cplusplus
}
#endif


#ifndef _EVC
inline int abs(int a)
{
    return a>=0 ? a : -a;
}
#endif



void ScanRightAAEdge(
                Point ps, Point pe,
                ScanLineList * scanlinelist,
                int startY, int height,
                const BitmapBufInfo * srcImg, const BitmapBufInfo * dstImg,
                int level);

void ScanLeftAAEdge(
                Point ps, Point pe,
                ScanLineList * scanlinelist,
                int startY, int height,
                const BitmapBufInfo * srcImg, const BitmapBufInfo * dstImg,
                int level);

void FillPolygon(
                ScanLineList * scanlinelist,
                int startY, int height,
                const BitmapBufInfo * srcImg, const BitmapBufInfo * dstImg,
                int level);

inline Pixel BilInearNC4A(Pixel* PColor0, Pixel* PColor1,unsigned long u_8,unsigned long v_8)
{
    unsigned long pm3_16=u_8*v_8;
    unsigned long pm2_16=(u_8<<8)-pm3_16;
    unsigned long pm1_16=(v_8<<8)-pm3_16;
    unsigned long pm0_16=(65535)-pm1_16-pm2_16-pm3_16;

    Pixel result;

    result.a =(unsigned char)((pm0_16*PColor0[1].a+pm2_16*PColor0[0].a+pm1_16*PColor1[1].a+pm3_16*PColor1[0].a)>>16);
    result.r =(unsigned char)((pm0_16*PColor0[1].r+pm2_16*PColor0[0].r+pm1_16*PColor1[1].r+pm3_16*PColor1[0].r)>>16);
    result.g =(unsigned char)((pm0_16*PColor0[1].g+pm2_16*PColor0[0].g+pm1_16*PColor1[1].g+pm3_16*PColor1[0].g)>>16);
    result.b =(unsigned char)((pm0_16*PColor0[1].b+pm2_16*PColor0[0].b+pm1_16*PColor1[1].b+pm3_16*PColor1[0].b)>>16);

    return result;
}

#endif  //__RENDERUTILITY_H__
